package com.kolon.business.mAccessMan.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kolon.framework.constant.Constant;
import com.kolon.framework.interfaces.SimpleController;
import com.kolon.framework.util.ComUtil;
import com.kolon.framework.util.MsgUtil;

@Controller("com.kolon.business.mAccessMan.controller.MAccessManApplyCancelController")
public class MAccessManApplyCancelController implements SimpleController {

	@SuppressWarnings("rawtypes")
	@RequestMapping(value="/business/mAccessMan/mAccessManApplyCancel.do")
	public ModelAndView controller(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// 도메인
		String url = MsgUtil.getMessage("xml.url");
		// 세션 아이디 및 암호 값을 불러옴
		HttpSession httpSession = request.getSession();
		Map userMap = (Map)httpSession.getAttribute(Constant.SESSION_USER_INFO);
		String id = (String)userMap.get("userId");
		String pw = (String)userMap.get("userPw");
		ModelAndView modelAndView = new ModelAndView();		
		StringBuffer buffer = new StringBuffer();
		buffer.append(url);			
		buffer.append("/access_man.aspx?command=").append("delete_visitor");
		buffer.append("&apply_seq=").append(ComUtil.nullChk(request.getParameter("ApplySeq"), ""));
		buffer.append("&userid=").append(id);
		// XML DOCUMENT 및 인증 처리
		ComUtil.getDocument(buffer.toString(), id, pw);
		String scriptType 	= "003";
		String message   	= "예약이 취소되었습니다.";
		String message_url = "/business/mAccessMan/mAccessManApplyList.do";		
		modelAndView.addObject("scriptType", scriptType);
		modelAndView.addObject("message", message);
		modelAndView.addObject("message_url", message_url);
		modelAndView.setViewName("/business/common/alert");
		// 리턴
		return modelAndView;
	}
}